feat: distance filter input in the configured display unit - #412
Merged
Conversation
First part of #10: a distance_unit plugin setting (m, km, ft, mi, nm) that drives what users see. Meters remain the internal unit everywhere (storage, SQL, filter wire format, REST API). - RedmineGtt::DistanceUnit: unit table, current/api_unit readers with fallback, to/from-meters conversion - distance column: header carries the unit (caption proc), list and CSV cells render converted via a QueriesHelper prepend - api_distance_unit setting reserved with meters as the only option, so the API contract can widen later without a settings migration - settings UI selects + en/ja/de locales The distance filter input and the nearby-watch radius field follow in separate PRs.
Second part of #10. The distance filter row displays and accepts its bounds in the configured unit: values coming from the server (meters) convert for display, and a submit hook on #query_form converts back to integer meters, so the wire format, saved queries and the API stay metric. The unit label renders next to the inputs. The hook binds via jQuery when present because core submits the form with $('#query_form').submit(), which bypasses native listeners.
There was a problem hiding this comment.
Pull request overview
Adds end-to-end support for entering and displaying the distance query filter in the configured distance unit while keeping the server/API contract in meters, completing the “filter input” portion of the multi-unit distance feature (#10) that started in #411.
Changes:
- Frontend: convert distance filter values from meters → configured unit for display, and convert back on
#query_formsubmit. - Backend: introduce
RedmineGtt::DistanceUnitand use it to render distance column/list + CSV in the configured unit. - Settings/i18n/tests: add distance unit settings UI, translations, and unit tests for conversion/parity.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/components/gtt-client/redmine/filters.ts |
Converts distance filter inputs between meters (wire) and configured display units; adds submit hook. |
src/components/gtt-client/redmine/filters.test.ts |
Adds Vitest coverage for unit table parity and display conversion trimming. |
lib/redmine_gtt/distance_unit.rb |
Adds server-side conversion utilities and unit tables. |
lib/redmine_gtt/patches/queries_helper_patch.rb |
Renders distance column and CSV values in the configured unit. |
lib/redmine_gtt/patches/issue_query_patch.rb |
Updates distance column caption to include the configured unit. |
lib/redmine_gtt.rb |
Applies the new QueriesHelper patch during setup. |
init.rb |
Adds default plugin settings for distance_unit and api_distance_unit. |
app/views/settings/gtt/_general.html.erb |
Adds settings UI for distance unit selection (display + reserved API unit). |
config/locales/en.yml |
Adds English strings for distance unit settings and options. |
config/locales/de.yml |
Adds German strings for distance unit settings and options. |
config/locales/ja.yml |
Adds Japanese strings for distance unit settings and options. |
test/unit/distance_unit_test.rb |
Adds unit tests for server-side conversion and unit selection behavior. |
test/unit/queries_helper_patch_test.rb |
Adds helper tests for column/CSV rendering under the configured unit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- unknown units fall back to meters instead of raising KeyError (the setting can be hand-edited, callers may pass user-supplied strings) - the CSV separator test derives its expectation from the locale instead of hardcoding '.'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2 of 3 for #10, stacked on #411 (diff shrinks to the frontend commit once it merges).
The distance filter row now works in the configured display unit:
metersToUnitValue, float-noise trimmed so a 25 km round trip shows25, not24.999999997), with the unit label rendered next to both bound inputs (incl. the between operator's upper bound)#query_formconverts the visible values back to integer meters, so the wire format, saved queries, permalinks and the API all stay metric — the server sees exactly what it always saw$('#query_form').submit(), which triggers jQuery-bound handlers but bypasses nativeaddEventListenerlisteners#gtt-defaultsplugin_settingspayload — no new plumbingVerified E2E in a browser with
distance_unit=km: wire value 500000 displays as500 km; typing100and applying producesv[distance][]=100000in the URL, correct (empty) result set, and the restored input shows100again. Unit tests: 4 new Vitest cases (unit table parity with the Ruby side, conversions, float-noise trimming, passthrough).